package com.codeduck.order.dubbo;

import com.codeduck.common.dubbo.IOrderDubboService;
import com.codeduck.common.response.OrderResponse;
import com.codeduck.common.response.ServiceResponse;
import com.codeduck.order.domain.OrderDO;
import com.codeduck.order.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author: <a href="mailto:codeduck@163.com">Codeduck</a>
 * @createDate: 2022-08-20
 */
@Service
@Slf4j
public class OrderDubboService implements IOrderDubboService {

    @Resource
    private IOrderService orderService;

    @Override
    public ServiceResponse<OrderResponse> createOrder(String userId, String commodityCode, int count) {
        log.info("生成订单请求 = [userId：{}，commodityCode：{}， orderCount：{} ]", userId, commodityCode, count);
        OrderDO order = orderService.createOrder(userId, commodityCode, count);
        OrderResponse orderResponse = OrderResponse.builder()
                .userId(userId)
                .orderNo(order.getOrderNo())
                .commodityCode(order.getCommodityCode())
                .amount(order.getAmount())
                .build();
        return ServiceResponse.asOk(orderResponse);
    }
}
